package utils.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import com.lanou.horo.myapplication.dbdao.FristTopDbEntity;

import java.util.ArrayList;
import java.util.List;

import dbdao.FristTopDBHelper;
import entity.RecommendedPageEntity;
import fragment.classicfragments.ClassifoimgViewpageFragment;

/**
 * Created by dllo on 15/11/26.
 */
public class RecommendViewPagerAdpter extends FragmentPagerAdapter {
private List<RecommendedPageEntity.FocusImagesEntity.ListEntity > image;

    public void addImages(List<RecommendedPageEntity.FocusImagesEntity.ListEntity > image){
        this.image = image;
        notifyDataSetChanged();
    }
    public RecommendViewPagerAdpter(FragmentManager fm) {
        super(fm);
    }


    @Override
    public Fragment getItem(int position) {
        RecommendedPageEntity.FocusImagesEntity.ListEntity images =
                image.get(position % image.size());
                String imgUrl = images.getPic();
        List<FristTopDbEntity> datas = new ArrayList<>();
        FristTopDbEntity entity = new FristTopDbEntity();
        entity.setPic(imgUrl);
        datas.add(entity);
        FristTopDBHelper.getInstance().saveHost(datas);
        return  ClassifoimgViewpageFragment.getInstance(imgUrl);
    }

    @Override
    public int getCount() {
        return image != null && image.size() > 0 ?  Integer.MAX_VALUE : 0;
    }
}
